﻿Imports WPFGlue.Framework

<Assembly: System.Windows.Markup.XmlnsDefinition("http://wpfglue.wordpress.com/commanding", "WPFGlue.Commanding")> 
<Assembly: System.Windows.Markup.XmlnsPrefix("http://wpfglue.wordpress.com/commanding", "c")> 

Namespace Commanding
    Public Class Commanding
        Inherits DependencyObject

        Public Shared ReadOnly CommandSetProperty As DependencyProperty = DependencyProperty.RegisterAttached("CommandSet", GetType(CommandBase), GetType(Commanding), New PropertyMetadata(AddressOf OnCommandSetChanged))
        Public Shared Function GetCommandSet(ByVal d As DependencyObject) As CommandBase
            Return d.GetValue(CommandSetProperty)
        End Function
        Public Shared Sub SetCommandSet(ByVal d As DependencyObject, ByVal value As CommandBase)
            d.SetValue(CommandSetProperty, value)
        End Sub
        Private Shared Sub OnCommandSetChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
            Dim c As IStickyComponent
            c = TryCast(e.OldValue, IStickyComponent)
            If c IsNot Nothing Then
                StickyComponentManager.Detach(d, c)
            End If
            c = TryCast(e.NewValue, IStickyComponent)
            If c IsNot Nothing Then
                StickyComponentManager.Attach(d, c)
            End If
        End Sub
    End Class
End Namespace
